package com.handinfo.uimenu.window;

import java.io.DataInputStream;
import java.io.IOException;

import javax.microedition.lcdui.Graphics;

import com.handinfo.engine.AbstractGameScreen;
import com.handinfo.engine.GameManager;
import com.handinfo.engine.net.GameProtocol;
import com.handinfo.game.ActorItem;
import com.handinfo.game.ActorItemEquip;
import com.handinfo.game.ActorRole;
import com.handinfo.uimenu.UIAbstractWindow;
import com.handinfo.uimenu.UIListener;
import com.handinfo.uimenu.UIManager;
import com.handinfo.uimenu.UIMessageBox;
import com.handinfo.uimenu.UIPopmenu;
import com.handinfo.uimenu.UITools;
import com.handinfo.uimenu.UIWindowFactory;
import com.handinfo.util.ArrayList;
import com.handinfo.util.Tools;
import com.test.touch.GameTouchManager;

public class UIQianghua extends UIAbstractWindow implements ILBHandler
{

	private final int STATE_SEL = 1;
	private final int STATE_DETAIL = 2;
	//
	private static final byte TYPE_PHY = 1;//物理强化
	private static final byte TYPE_MAGIC = 2;//法术强化
	private static final byte TYPE_DEFENSE = 3;//防具强化
	// 索引
	private ActorItemLBHandler m_bag_handler;
	private ActorItem[] m_items;
	private byte m_type;//强化类型
	private ActorItem m_item;//选中的

	private long m_money_need;
	private int m_level_max;
	private int m_level_fail;
	private int m_add_ph;
	private int m_add_magic_min;
	private int m_add_magic_max;
	private int m_add_ph_def;
	private int m_add_magic_def;
	private ActorItem[] m_marter;
	private int[] m_nums;
	//
	private boolean m_isUseProtect;
	private ActorItem m_baohufu;
	private int m_num_baohufu;//保护符的数目

	public UIQianghua(int id)
	{
		super(id);
		setBounds(UITools.X_BG, UITools.Y_BG, UITools.W_BG, UITools.H_BG);
		//
		m_items = getItems();
		m_bag_handler = new ActorItemLBHandler(this);
		m_bag_handler.setLabelByGroupIndex(1);
	}
    /** 强化过滤 */
	private ActorItem[] getItems()
	{
		ActorItem[] items = GameManager.getInstance().m_role.m_bag_goods;
		ArrayList list = new ArrayList();
		for (int i = 0; i < items.length; i++) {
			if (items[i] == null) {
				continue;
			}
			if (!items[i].isCanQianghua()) {
				continue;
			}
			list.addElement(items[i]);
//			if (items[i].m_type_detail == ActorItem.TYPE_EQUIPMENT_WEAPON_SIN
//					|| items[i].m_type_detail == ActorItem.TYPE_EQUIPMENT_WEAPON_MUL
//					|| items[i].m_type_detail == ActorItem.TYPE_EQUIPMENT_WEAPON_MAG
//					 ) {
//				list.addElement(items[i]);
//			}
		}
		int size = list.size();
		if (size == 0) {
			return null;
		}
		else {
			ActorItem[] result = new ActorItem[size];
			for (int i = 0; i < result.length; i++) {
				result[i] = (ActorItem) list.elementAt(i);
			}
			return result;
		}
	}

	public void updateWindow()
	{
		m_items = getItems();
		m_bag_handler.resetBagData();
		m_item = (ActorItem) m_bag_handler.getCurrentBagItem();//重新选择
	}

	protected void actionOnIndexChanged()
	{
		m_bag_handler.updateOnStateOrIndexChanged();
	}

	public static void gotoQianghua()
	{
		UIQianghua qianghua = (UIQianghua) UIWindowFactory.createWindow(UIWindowFactory.WINDOW_QIANGHUA);
		qianghua.setWindowStatus(qianghua.STATE_SEL);
		qianghua.m_index = -2;
		qianghua.setWindowIndex(0);
		UIManager.getInstance().addWindow(qianghua);
	}

	public static void recvMessage(int orderId, DataInputStream dis) throws IOException
	{
		UIQianghua qianghua = (UIQianghua) UIManager.getInstance().getWindowById(UIWindowFactory.WINDOW_QIANGHUA);
		Tools.debugPrintln("UIQianghua orderId="+orderId);
		switch (orderId) {
			case GameProtocol.CS_ACTORITEM_QIANGHUA_ENTER: {//NPC 入口
				short state = dis.readShort();
				String info = dis.readUTF();
				if (state == 0) {
					if (!info.equals("")) {
						GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, info);
					}
					return;
				}
				if (qianghua != null) {
					return;
				}
				gotoQianghua();
			}
				break;
			case GameProtocol.CS_ACTORITEM_QIANGHUA_NEW: {
				if (qianghua == null) {
					return;
				}
				short state = dis.readShort();
				String info = dis.readUTF();
				if (!info.equals("")) {
					GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, info);
				}
				switch (state) {
					case -1://道具被分解了
						qianghua.setWindowStatus(qianghua.STATE_SEL);
						break;
					case 0:
						return;
					case 1:
						GameManager.getInstance().m_game_message.sendActorItemQianghuaInfoNew(qianghua.m_type,
								qianghua.m_item.m_guid);//重新请求强化数据
						break;
				}
			}
				break;
			case GameProtocol.CS_ACTORITEM_QIANGHUA_INFOS_NEW: {
				if (qianghua == null) {
					return;
				}
				short state = dis.readShort();
				String info = dis.readUTF();
				if (!info.equals("")) {
					GameManager.getInstance().addSystemInfo(GameManager.SYSTEM_INFO_TYPE_B, info);
				}
				if (state == 0) {
					return;
				}
				qianghua.m_money_need = dis.readLong();
				qianghua.m_level_max = dis.readInt();
				qianghua.m_level_fail = dis.readInt();
				qianghua.m_add_ph = dis.readInt();
				qianghua.m_add_magic_min = dis.readInt();
				qianghua.m_add_magic_max = dis.readInt();
				int num_marter = dis.readInt();
				ActorRole role = GameManager.getInstance().m_role;
				if (num_marter == 0) {
				}
				else {
					ActorItem[] items = new ActorItem[num_marter];
					int[] nums = new int[num_marter];
					for (int i = 0; i < num_marter; i++) {
						items[i] = new ActorItem();
						items[i].m_key = dis.readUTF();
						items[i].m_name = dis.readUTF();
						items[i].m_iconId = dis.readShort();
						items[i].m_iconCoverId = dis.readShort();
						items[i].m_num = dis.readInt();
					}
					qianghua.m_marter = items;
					for (int i = 0; i < nums.length; i++) {
						nums[i] = role.getItemNum(ActorItem.TYPE_BAG_ROLE, items[i].m_key);
					}
				}
				ActorItem item = new ActorItem();
				item.m_key = dis.readUTF();
				item.m_name = dis.readUTF();
				item.m_iconId = dis.readShort();
				item.m_iconCoverId = dis.readShort();
				item.m_num = dis.readInt();
				qianghua.m_add_ph_def = dis.readInt();
				qianghua.m_add_magic_def = dis.readInt();
				qianghua.m_baohufu = item;
				qianghua.m_num_baohufu = role.getItemNum(ActorItem.TYPE_BAG_ROLE, item.m_key);
				//
				qianghua.setWindowStatus(qianghua.STATE_DETAIL);
			}
				break;
		}
	}

	public static void test()
	{
		gotoQianghua();
	}

	protected void paintContent(Graphics g)
	{
		UITools.paintBackGround(g, m_x, m_y, m_w, m_h, "强化");
		switch (m_state) {
			case STATE_SEL:
				paintSel(g);
				break;
			case STATE_DETAIL:
				paintDetail(g);
				break;
		}
	}

	private void paintSel(Graphics g)
	{
		int tempY = m_y + UITools.INITY_CONTENT - (UITools.H_LABEL + UITools.IH_RECTS);
		m_bag_handler.m_row = 9;
		m_bag_handler.setInitXY(tempY);
		m_bag_handler.paintBag(g);
		m_bag_handler.paintBagFocused(g);
		m_bag_handler.paintDrag(g);
		m_bag_handler.paintDescribe(g);
	}

	private void paintDetail(Graphics g)
	{
		String temp = m_isUseProtect ? "单击关闭保护符" : "单击开启保护符";
		UITools.paintBackGround(g, m_x, m_y, m_w, m_h, "强化锻造", temp, true, true);
		//
		int initX = m_x + UITools.INITX_CONTENT;
		int initY = m_y + UITools.INITY_CONTENT;
		int tempX = initX;
		int tempY = initY;
		//
		int H_INFO = 150;
		UITools.paintContentRect(g, tempX, tempY, UITools.W_RECT, H_INFO);
		tempX += UITools.IW_RECT_CONTENT;
		tempY += UITools.IH_RECT_CONTENT;
		//名称
		temp = "装备：";
		g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_NOS));
		g.drawString(temp, tempX, tempY, 0);
		tempX += AbstractGameScreen.s_font.stringWidth(temp);
//		g.drawString(m_item.m_name, tempX, tempY, 0);
		ActorItemEquip equip = (ActorItemEquip) m_item;
		if (m_type == TYPE_PHY) {
			ActorItem.drawName(g, "+" + equip.m_level_phy + m_item.m_name, tempX, tempY, m_item.m_xiyoudu);
		}
		else if (m_type == TYPE_DEFENSE){
			ActorItem.drawName(g, "+" + equip.m_level_defence + m_item.m_name, tempX, tempY, m_item.m_xiyoudu);
		}
		else {
			ActorItem.drawName(g, "+" + equip.m_level_magic + m_item.m_name, tempX, tempY, m_item.m_xiyoudu);
		}
		tempY += AbstractGameScreen.FONT_H;
		//等级
		tempX = initX + UITools.IW_RECT_CONTENT;
		if (m_type == TYPE_PHY) {
			paintLevel(g, tempX, tempY, "物理", equip.m_level_phy, m_level_max);
		}
		else if(m_type == TYPE_DEFENSE){
			paintLevel(g, tempX, tempY, "防御", equip.m_level_defence, m_level_max);
		}
		else {
			paintLevel(g, tempX, tempY, "法术", equip.m_level_magic, m_level_max);
		}
		tempY += AbstractGameScreen.FONT_H;
		//物理防御强化
		if(m_add_ph_def != 0){
			tempX = initX + UITools.IW_RECT_CONTENT;
			temp = "物理防御：" + "+" + m_add_ph_def;
			g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_NOS));
			g.drawString(temp, tempX, tempY, 0);
			tempY += AbstractGameScreen.FONT_H;
		}
		//法术防御强化
		if (m_add_magic_def > 0) {
			tempX = initX + UITools.IW_RECT_CONTENT;
			temp = "法术防御：" + "+" + m_add_magic_def;
			g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_NOS));
			g.drawString(temp, tempX, tempY, 0);
			tempY += AbstractGameScreen.FONT_H;
		}
		//物理强化
		if (m_add_ph != 0) {
			tempX = initX + UITools.IW_RECT_CONTENT;
			temp = "物理攻击：" + "+" + m_add_ph ;
			g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_NOS));
			g.drawString(temp, tempX, tempY, 0);
			tempY += AbstractGameScreen.FONT_H;
		}
		//法术强化 - 最小法攻
		if (m_add_magic_min > 0) {
			tempX = initX + UITools.IW_RECT_CONTENT;
			temp = "最小法术攻击：" + "+" + m_add_magic_min;
			g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_NOS));
			g.drawString(temp, tempX, tempY, 0);
			tempY += AbstractGameScreen.FONT_H;
		}
		if (m_add_magic_max > 0) {
			tempX = initX + UITools.IW_RECT_CONTENT;
			temp = "最大法术攻击：" + "+" + m_add_magic_max;
			g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_NOS));
			g.drawString(temp, tempX, tempY, 0);
			tempY += AbstractGameScreen.FONT_H;
		}
		//消耗
		tempX = initX + UITools.IW_RECT_CONTENT;
		g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_NOS));
		g.drawString("消耗资源 ：", tempX, tempY, 0);
		tempY += AbstractGameScreen.FONT_H;
		//金钱
		tempX = initX + UITools.IW_RECT_CONTENT;
		temp = "金钱：";
		g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_NOS));
		g.drawString(temp, tempX, tempY, 0);
		tempX += AbstractGameScreen.s_font.stringWidth(temp);
		UITools.paintMoneyGameLT(g, tempX, tempY, m_money_need, false);
		tempY += AbstractGameScreen.FONT_H;
		//材料
		if (m_items != null) {
			tempX = initX + UITools.IW_RECT_CONTENT;
			for (int i = 0, len = m_items.length - 1; i < len; i++) {
				paintMater(g, tempX, tempY, i);
				tempY += AbstractGameScreen.FONT_H;
			}
		}

		//描述
		tempX = initX;
		tempY = initY + (H_INFO + UITools.IH_RECTS);
		UITools.paintContentRect(g, tempX, tempY, UITools.W_RECT, UITools.H_RECT - (H_INFO + UITools.IH_RECTS));
		tempX += UITools.IW_RECT_CONTENT;
		tempY += UITools.IH_RECT_CONTENT;
		if (m_isUseProtect) {
			temp = "使用";
			tempX = initX + UITools.IW_RECT_CONTENT;
			g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_NOS));
			g.drawString(temp, tempX, tempY, 0);
			tempX += AbstractGameScreen.s_font.stringWidth(temp) + 2;
			//
			g.setColor(Tools.GREEN);
			temp = m_baohufu.m_num + "个" + m_baohufu.m_name;
			g.drawString(temp, tempX, tempY, 0);
			tempY += AbstractGameScreen.FONT_H;
			//
			temp = "失败不降级";
			tempX = initX + UITools.IW_RECT_CONTENT;
			g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_NOS));
			g.drawString(temp, tempX, tempY, 0);
		}
		else {
			temp = "不使用";
			tempX = initX + UITools.IW_RECT_CONTENT;
			g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_NOS));
			g.drawString(temp, tempX, tempY, 0);
			tempX += AbstractGameScreen.s_font.stringWidth(temp) + 2;
			//
			g.setColor(Tools.RED);
			temp = m_baohufu.m_num + "个" + m_baohufu.m_name;
			g.drawString(temp, tempX, tempY, 0);
			tempY += AbstractGameScreen.FONT_H;
			//
			if (m_level_fail == 0) {
				temp = "失败不降级";
			}
			else if (m_level_fail == -1) {
				temp = "失败道具将被销毁";
			}
			else {
				temp = "失败降级至+" + m_level_fail;
			}
			tempX = initX + UITools.IW_RECT_CONTENT;
			g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_NOS));
			g.drawString(temp, tempX, tempY, 0);
		}

	}

	private void paintLevel(Graphics g, int tempX, int tempY, String temp, int level_now, int level_max)
	{
		g.setColor(UIManager.getPaletteColor(UIManager.COLOR_WORD_NOS));
		g.drawString(temp, tempX, tempY, 0);
		tempX += AbstractGameScreen.s_font.stringWidth(temp);
		temp = "+" + String.valueOf(level_now);
		g.drawString(temp, tempX, tempY, 0);
		tempX += AbstractGameScreen.s_font.stringWidth(temp);
		temp = "强化到+";
		g.drawString(temp, tempX, tempY, 0);
		tempX += AbstractGameScreen.s_font.stringWidth(temp);
		int num = level_now + 1;
		if (num < level_max) {
			temp = String.valueOf(num);
		}
		else {
			temp = String.valueOf(level_max);
		}
		g.drawString(temp, tempX, tempY, 0);
	}

	private void paintMater(Graphics g, int x, int y, int index)
	{
		if (m_marter == null) {
			return;
		}
		if (m_marter[index] == null) {
			return;
		}
		int num_need = m_nums[index];
		if (m_marter[index].m_num > num_need) {
			g.setColor(Tools.RED);
		}
		else {
			g.setColor(Tools.GREEN);
		}
		m_marter[index].drawIcon(g, x, y, 0);
		x += UITools.W_BAG;
		g.drawString(m_marter[index].m_name, x, y, 0);
		x += AbstractGameScreen.s_font.stringWidth(m_marter[index].m_name);
		g.drawString(m_marter[index].m_num + "/" + num_need, x, y, 0);
	}

	protected void keyLogic()
	{
		switch (m_state) {
			case STATE_SEL:
				int dir = m_bag_handler.keyDir(AbsLBHandler.TYPE_BAG);
				switch (dir) {
					case AbsLBHandler.TYPE_DIR_UNPRO:
						break;
					case AbsLBHandler.TYPE_DIR_NONE:
						if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)
								|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)) {
							ActorItem item = (ActorItem) m_bag_handler.getCurrentBagItem();
							clickBagItem(item);
						}
						else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
							close();
						}
						break;
					default:// 有返回值
						this.setWindowIndex(dir);
						break;
				}
				break;
			case STATE_DETAIL:
				if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
					setWindowStatus(STATE_SEL);
					m_isUseProtect = false;
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
						|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
					final UIMessageBox messageBox = (UIMessageBox) UIManager.getInstance().createWindow(
							UIWindowFactory.WINDOW_MESSAGEBOX);
					messageBox.setMessage("强化将消耗一定的金币和材料,是否强化?");
					messageBox.addListener(new UIListener() {

						public void actionPerformed()
						{
							if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
									|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
								GameManager.getInstance().m_game_message.sendActorItemQianghuaNew(m_type,
										m_item.m_guid,
										m_isUseProtect ? (byte) 1 : 0, m_baohufu.m_key, m_baohufu.m_num);
								UIManager.getInstance().removeWindow(messageBox);
							}
							else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
								UIManager.getInstance().removeWindow(messageBox);
							}
						}
					});
				}
				else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_KEY0)) {
					if (m_isUseProtect) {
						m_isUseProtect = false;
					}
					else {
						if (m_baohufu.m_num > m_num_baohufu) {//不够
							GameManager.getInstance().addMessage("您背包中的" + m_baohufu.m_name + "不足,请先购买");
						}
						else {
							m_isUseProtect = true;
						}
					}

				}
				break;
		}
	}

	private void clickBagItem(final ActorItem item)
	{
		if (item == null) {
			return;
		}
		final UIPopmenu popmenu; 
	    if( item.m_type == ActorItem.TYPE_GOODS_EQUIPMENT){
	    	switch (item.m_type_detail) {
				case ActorItem.TYPE_EQUIPMENT_WEAPON_MAG:
				case ActorItem.TYPE_EQUIPMENT_WEAPON_MUL:
				case ActorItem.TYPE_EQUIPMENT_WEAPON_SIN:
					popmenu = (UIPopmenu) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_POPMENU);
					popmenu.setPopmenus(new String[] { "物理强化", "法术强化", "返回" });
					popmenu.addListener(new UIListener() {

						public void actionPerformed()
						{
							if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
									|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
								switch (popmenu.getCurrentIndex()) {
									case 0://wuli
										sendDetail(TYPE_PHY, item);
										break;
									case 1:
										sendDetail(TYPE_MAGIC, item);
										break;
								}
								UIManager.getInstance().removeWindow(popmenu);
							}
							else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
								UIManager.getInstance().removeWindow(popmenu);
							}
						}

						private void sendDetail(byte type, ActorItem item)
						{
							m_type = type;
							m_item = item;
							GameManager.getInstance().m_game_message.sendActorItemQianghuaInfoNew(m_type, item.m_guid);
						}
					});
					break;
				case ActorItem.TYPE_EQUIPMENT_HEAD:
				case ActorItem.TYPE_EQUIPMENT_CLOSE:
				case ActorItem.TYPE_EQUIPMENT_TROUSERS:
				case ActorItem.TYPE_EQUIPMENT_BELT:
				case ActorItem.TYPE_EQUIPMENT_SHOES:
					popmenu = (UIPopmenu) UIManager.getInstance().createWindow(UIWindowFactory.WINDOW_POPMENU);
					popmenu.setPopmenus(new String[] { "防具强化","返回" });
					popmenu.addListener(new UIListener() {

						public void actionPerformed()
						{
							if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_LEFT_SOFT)
									|| AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_A)) {
								switch (popmenu.getCurrentIndex()) {
									case 0://防具
										sendDetail(TYPE_DEFENSE, item);
										break;
								}
								UIManager.getInstance().removeWindow(popmenu);
							}
							else if (AbstractGameScreen.haveKeyPressed(AbstractGameScreen.GK_RIGHT_SOFT)) {
								UIManager.getInstance().removeWindow(popmenu);
							}
						}

						private void sendDetail(byte type, ActorItem item)
						{
							m_type = type;
							m_item = item;
							GameManager.getInstance().m_game_message.sendActorItemQianghuaInfoNew(m_type, item.m_guid);
						}
					});
					break;
			}
	    }
	}

	protected int countGroupId(int mIndex)
	{
		return 0;
	}

	protected int countGroupIndex(int mGroupId, int mIndex)
	{
		return mIndex;
	}

	public int getUpIndex()
	{
		return AbsLBHandler.TYPE_DIR_UNPRO;
	}

	public int getDownIndex()
	{
		return AbsLBHandler.TYPE_DIR_UNPRO;
	}

	public int getLeftIndex()
	{
		return AbsLBHandler.TYPE_DIR_UNPRO;
	}

	public int getRightIndex()
	{
		return AbsLBHandler.TYPE_DIR_UNPRO;
	}

	public int getWindowIndex()
	{
		return m_index;
	}

	public int getGroupIndex()
	{
		return this.m_groupIndex;
	}

	public int getFirstIndex(int id_comp)
	{
		return 0;
	}

	public Object[] getBagDatas()
	{
		return m_items;
	}
	///////////////////////////////////
	int[][] qianghua;
	protected void registerTouch() {
		clearAllRects();
		registerNormalSoft();
		switch (m_state) {
		case STATE_SEL:
			int tempY = m_y + UITools.INITY_CONTENT - (UITools.H_LABEL + UITools.IH_RECTS);
			m_bag_handler.m_row = 9;
			m_bag_handler.setInitXY(tempY);
			tempY = m_bag_handler.m_y_bag;
			qianghua = new int[m_bag_handler.m_row*m_bag_handler.NUM_BAG_COL][];
			for (int i = 0; i < m_bag_handler.m_row; i++) {
				int tempX = m_bag_handler.m_x_bag;
				for (int j = 0; j < m_bag_handler.NUM_BAG_COL; j++) {
					qianghua[i * m_bag_handler.NUM_BAG_COL + j] = new int[] { tempX,
							tempY, m_bag_handler.RW_BAG, m_bag_handler.RH_BAG };
					tempX += m_bag_handler.RW_BAG;
				}
				tempY += m_bag_handler.RH_BAG;
			}
			initTouchRect(qianghua);
			initTouchRect(new int[][]{
					{332,39,17,32},
					{332,204,17,32},
			});
			break;
		case STATE_DETAIL:
//			paintDetail(g);
			break;
		}
		
	}
	protected void onTouchRect(int[][] rect, int touchid) {
		switch (m_state) {
		case STATE_SEL:
			if (qianghua == rect) {
				if (m_index == touchid) {
					GameTouchManager.keyPressedFire();
				} else {
					setWindowIndex(touchid);
				}
			} else {
				switch(touchid) {
				case 0:
					GameTouchManager.keyPressedDir(1);
					break;
				case 1:
					GameTouchManager.keyPressedDir(3);
					break;
				}
			}
			break;
		case STATE_DETAIL:
//			paintDetail(g);
			break;
		}
	}
	
	

}
